package com.jsb.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bokecc.bean.UploadReq;
import com.bokecc.bean.VedioInfo;
import com.jsb.common.config.Global;
import com.jsb.mapper.DramaResourceMapper;
import com.jsb.model.Admin;
import com.jsb.model.DramaResource;
import com.jsb.model.DramaResourceExample;

@Service
public class DramaResourceService{
	
	@Resource
	private DramaResourceMapper dramaResourceMapper;
	
	public void addDramaResource(DramaResource dramaResource) {
		dramaResourceMapper.insertSelective(dramaResource);
	}
	
	public void delDramaResourceByVid(String vid) {
		dramaResourceMapper.deleteByPrimaryKey(vid);
	}
	
	public void updateDramaResource(DramaResource dramaResource) {
		dramaResourceMapper.updateByPrimaryKeySelective(dramaResource);
	}
	
	public void updateDramaResourceByExample(DramaResource dramaResource,DramaResourceExample dramaResourceExample){
	    dramaResourceMapper.updateByExampleSelective(dramaResource,dramaResourceExample);
	}
	
	public DramaResource getDramaResourceByVid(String vid) {
		return dramaResourceMapper.selectByPrimaryKey(vid);
	}
	
	public List<DramaResource> getPageDramaResource(DramaResourceExample dramaResourceExample) {
		return dramaResourceMapper.selectPage(dramaResourceExample);
	}
	
	public int countDramaResource(DramaResourceExample dramaResourceExample) {
		return dramaResourceMapper.countByExample(dramaResourceExample);
	}
	
	public List<DramaResource> selectByExample(DramaResourceExample example){
	    return dramaResourceMapper.selectByExample(example);
	}

	public void insertDramaResource(VedioInfo vedioInfo, UploadReq uploadReq, Admin admin) {
		DramaResource dramaResource = new DramaResource();
		dramaResource.setCreateDate(new Date());
		dramaResource.setDramaId(uploadReq.getDramaId());
//		dramaResource.setCreateUser(admin.getId());
		dramaResource.setDelflag(Global.SHOW);
		dramaResource.setFileName(uploadReq.getFilename());
		dramaResource.setMd5(uploadReq.getMd5());
		dramaResource.setStatus(Global.PAYPENDING);
		dramaResource.setTitle(uploadReq.getTitle());
		dramaResource.setVid(vedioInfo.getVideoid());
		dramaResource.setChunkurl(vedioInfo.getChunkurl());
		dramaResource.setMetaurl(vedioInfo.getMetaurl());
		dramaResource.setServicetype(vedioInfo.getServicetype());
		dramaResourceMapper.insert(dramaResource);
	}
}
